package com.wx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wx.pojo.SourceDetail;
import com.wx.service.SourceDetailService;
/**
 * 展示服务的详细信息
 * @author gzcadmin
 *
 */
@Controller
@RequestMapping("/sourceDetail")
public class SourceDetailController {

	@Autowired
	private SourceDetailService sourceDetailService;
	
	/**
	 * 查询商品详细信息通过商品id
	 * @param sourceId
	 * @return
	 */
	@RequestMapping(value="/findDetailById" ,method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> findSourceById(
			@RequestParam("sourceId") Integer sourceId){
		
		Map<String,Object>modelMap=new HashMap<String,Object>();
		SourceDetail sourceDetail = sourceDetailService.findSourceById(sourceId);
		if(sourceDetail==null) {
			modelMap.put("errno", 1);
			modelMap.put("errorMsg", "商品信息错误");
			return modelMap;
		}
		modelMap.put("errno", 0);
		modelMap.put("sourceDetail", sourceDetail);
		return modelMap;
	}
	/**
	 * 查询详细信息通过用户id
	 * 查询个人发布信息
	 * @param userId
	 * @return
	 */
	@RequestMapping(value="/findDetailByUserId" ,method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> findPublishSourceByUserId(
			@RequestParam("userId") String userId){
		Map<String,Object>modelMap=new HashMap<String,Object>();
		List<SourceDetail>sourceDetailList =sourceDetailService.findPublishSourceByUserId(userId);
		if(sourceDetailList.isEmpty() || sourceDetailList.size()<0) {
			modelMap.put("errno",1);//查询个人发布信息失败
			return modelMap;
		}
		modelMap.put("errno", 0);
		modelMap.put("sourceDetailList", sourceDetailList);
		return modelMap;
	}
	
}
